package com.calvin.study.config.security;

import java.io.IOException;

import javax.servlet.ServletException;

import org.springframework.security.web.DefaultRedirectStrategy;
import org.springframework.security.web.RedirectStrategy;
import org.springframework.security.web.session.SessionInformationExpiredEvent;
import org.springframework.security.web.session.SessionInformationExpiredStrategy;

import com.calvin.study.base.ResponseModel;


public class CustomExpiredSessionStrategy implements SessionInformationExpiredStrategy {

	// 页面跳转逻辑处理
	private RedirectStrategy redirectStrategy = new DefaultRedirectStrategy();

	@Override
	public void onExpiredSessionDetected(SessionInformationExpiredEvent event) throws IOException, ServletException {
		//1.页面跳转
		//redirectStrategy.sendRedirect(event.getRequest(), event.getResponse(), "/login.html");
		
		//2.json数据交互
		event.getResponse().setContentType("application/json;charset=utf-8");
		event.getResponse().getWriter().write(ResponseModel.error("您的登录已超时或已在另一台机器登录被迫下线").toJson());
	}

}
